import numpy as np
from scipy.linalg import svd
if __name__ == '__main__':
    A = np.array([
        [1, 3, 0, 2], [0, 0, 1, 4], [1, 3, 1, 6]
    ])

    _, s, Vh = svd(A)
    tol = max(A.shape) * np.spacing(max(s))
    r = np.sum(s > tol)
    null_manual = Vh[r:].T
    print(f"SVD计算零空间:\n{null_manual}")

